package org.grottarossa.tms.ui.console;

import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BasePanel;


import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Panel;


/**
 * <p>Componente grafico gestito da un {@link ConsolePresenter}</p>
 *
 * @author 
 */
public abstract class ConsoleView extends BasePanel
{
	private static final long serialVersionUID = 5093367146546426751L;

	private ConsolePresenter m_presenter;

	public ConsoleView() throws DriverException
	{
		super(null, null);
	}

	/**
	 * Metodo di utilit� che dispone i componenti specificati all'interno di in un {@link HorizontalSplitPanel} predimensionato per questa {@link ConsoleView}
	 * @param children componenti da disporre orizzontalmente
	 * @return un {@link HorizontalSplitPanel} non associato ad alcun {@link ComponentContainer}
	 */
	protected HorizontalSplitPanel getHorizontalSplitPanel(Component... children)
	{
		HorizontalSplitPanel result = new HorizontalSplitPanel();
		for (Component c: children)
			result.addComponent(c);
		result.setSplitPosition(300, Sizeable.UNITS_PIXELS);
		result.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		result.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		return result;
	}

	/**
	 * @return associa un {@link ConsolePresenter presenter} a questa {@link ConsoleView}
	 */
	public void setPresenter(ConsolePresenter presenter) {
		this.m_presenter = presenter;
	}

	/**
	 * @return il {@link ConsolePresenter presenter} associato a questa {@link ConsoleView}
	 */
	public ConsolePresenter getPresenter() {
		return m_presenter;
	}

	public void initialize(ApplicationSession appSession)
	{
		m_appSession = appSession;
		this.initializeComponents();
	}
}
